/**
 * Copyright (C), 2015-2018, XXX有限公司
 * FileName: MutiDataSourceProperties
 * Author:   zhouheng
 * Date:     2018/6/20 21:09
 * Description: 多数据源配置文件
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.hengby.hengcrud.config.mutidatasource;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * 〈一句话功能简述〉<br> 
 * 〈多数据源配置文件〉
 *
 * @author zhouheng
 * @create 2018/6/20
 * @since 1.0.0
 */
@Component
@ConfigurationProperties(prefix = "muti-datasource")
public class MutiDataSourceProperties {
    public static final String PREFIX = "muti-datasource";

    public String deaultDataSourceName = "dataSourceMaster";

    @Value("${muti-datasource.url}")
    public String url;
    @Value("${muti-datasource.username}")
    public String username;
    @Value("${muti-datasource.password}")
    public String password;
    @Value("${muti-datasource.driver-class-name}")
    public String driverClassName;

    private String validationQuery = "SELECT 'x'";

    public void config(DruidDataSource dataSource) {
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        dataSource.setDriverClassName(driverClassName);
        dataSource.setValidationQuery(validationQuery);
    }
}